/*
 * @Author: your name
 * @Date: 2021-09-08 14:11:05
 * @LastEditTime: 2021-09-14 11:58:09
 * @LastEditors: Please set LastEditors
 * @Description: 维保成员打卡记录相关
 * @FilePath: \weplus_weibao\src\setup\maintenanceteam\MemberMarkRecordsSetup.js
 */
import { getCurrentInstance } from 'vue';
import { apiService } from '../../api/apiService';
import { showServerError } from '../../util/MessageDeal';
import { getMarkRecordByPage } from '../../api/server';
import moment from 'moment';

export default function useMemberMarkRecordsSetup () {
    const ctx = getCurrentInstance();
    const $st = ctx.appContext.config.globalProperties.$st;
    const statusMap = new Map([
        ['0', $st('unknow')], ['1', $st('At_work')], ['2', $st('On_standby')], ['3', $st('Resting')]
    ]);
    // 获取指定account的打卡记录
    const queryMarkRecords = (account, pageSize, page, search) => {
        return new Promise((resolve, reject) => {
            apiService({
                api: getMarkRecordByPage,
                param: {
                    n: pageSize,
                    page: page,
                    account: account,
                    ...search
                },
                success: (data) => {
                    const markRecords = data.value;
                    for (var i = 0; i < markRecords.length; i++) {
                        markRecords[i].createtime = moment(markRecords[i].createtime).format('YYYY-MM-DD HH:mm:ss');
                        markRecords[i].statusStr = statusMap.get(markRecords[i].status) || markRecords[i].status;
                    }
                    resolve(data);
                },
                fail: (data) => {
                    showServerError(data);
                    reject(data);
                }
            });
        });
    };
    return {
        queryMarkRecords
    };
}
